package com.viathink.vip.web.controller;

import com.viathink.frame.core.dao.BaseService;
import com.viathink.frame.core.web.controller.BaseControllerImpl;
import com.viathink.frame.core.web.domain.Result;
import com.viathink.sys.domain.SysDictionary;
import com.viathink.sys.domain.query.SysDictionaryQuery;
import com.viathink.sys.service.SysDictionaryService;
import com.viathink.vip.domain.VipCustomer;
import com.viathink.vip.domain.query.VipCustomerQuery;
import com.viathink.vip.service.VipCustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 会员信息的基本操作
 *
 * @author baijian
 * @date 20170525
 */
@Controller
@RequestMapping("/vip/customer")
public class VipCustomerContoller extends BaseControllerImpl<VipCustomer, VipCustomerQuery> {
    private Logger log = LoggerFactory.getLogger(VipCustomerContoller.class);

    @Autowired
    private VipCustomerService vipCustomerService;
    @Override
    protected BaseService<VipCustomer> getBaseService() {
        return vipCustomerService;
    }

    /**
     * 查询当前分页下vip信息数量  与分页有关
     * @param query
     * @param pageable
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryCount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Result queryCount(@RequestParam(required=false) VipCustomerQuery query, @PageableDefault Pageable pageable) {
        int count = 0;
        Page page = null;
        try {
            page = vipCustomerService.queryPageList(query, pageable);
            count = page.getNumberOfElements();
        } catch (Exception e) {
            log.error("获取数量失败:" + path.getEntityName(), e);
            return new Result(Result.Status.ERROR, "获取数量失败！");
        }
        List list = new ArrayList();
        list.add(count);
        list.add(page.getNumber());
        return new Result(Result.Status.OK, list);
    }

}
